<?
	require_once "../../_func/__Global.php";
	require_once "../../_func/__Local.php";
	require_once "../../_func/__MysqlFunc.php";
	require_once "../../_func/_MngFunc.php";
	require_once "../../_func/_Validation.php";
	require_once "../../_func/_CodeFunc.php";
	
	
	if ( ValidCheck_isSelfRequest($_SERVER['HTTP_REFERER']) ) {
		if ( $mode == 'r' ) {
			//get parameter
			$jbnh_name 			= $param->getString('jbnh_name');
			$nhcode_item1 		= $param->getString('nhcode_item1');
			
			//공백허용하지 않는것을 먼저 등록하여 유효성 검사
			$insert_arr = array(
				'jbnh_name'			=> $jbnh_name,
			);
			$isValid = true;
			foreach( $insert_arr as $key => $val )
			{
				if (!ValidCheck_isNotEmpty($val)) {
					errMsg($VALIDATE_ERROR_MESSAGE);
					$isValid = false;
				}
			}
			
			//품목체크여부 검사
			if ( $isValid && ($nhcode_item1 != null) && ($nhcode_item1 != "") )
				$isValid = true;
			else
				$isValid = false;
				
			if ( !$isValid )
				errMsg("품목을 체크해 주세요");
			else
			{
				//농협명 등록후 농협코드 취득
				$jbnh_seq	= NHInsert( $insert_arr );
				
				
				//품목 등록
				if( $jbnh_seq > 0 )
				{
					if ( is_array( $nhcode_item1 ) ) {
						foreach( $nhcode_item1 as $key => $val )
						{
							$sub_arr = array(
								'jbnh_seq'		=> $jbnh_seq,
								'nhcode_item1'	=> $val,
							);		
							NHCodeInsert($sub_arr);
							unset($sub_arr);
						}
					}
					cacheControl(0);
					ob_clean();
					jserrorPop("등록되었습니다.", true, true);
				}
			}
		}
		else {
			errMsg("비정상적인 접근입니다.");
		}
	} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>코드등록</title>
<link href="/css/layout.css" type="text/css" rel="stylesheet" />
<script src="/js/mng.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		jQuery.validator.setDefaults({
			onkeyup:false,
			onclick:false,
			onfocusout:false,
			showErrors:function(errorMap, errorList){
				$(errorList[0].element).focus();
				alert(errorList[0].message);
			}
		});
		$("#frm").validate({
			rules: {
				jbnh_name:			{required: true},
				"nhcode_item1[]":	{required: true}
			},
			messages: {
				jbnh_name:			{required: "농협명을 입력하세요"},
				"nhcode_item1[]":	{required: "품목을 체크하세요"}
			},
			success: function(label) {
				$('#sbmtBtn').remove();
			}
		});
	});
</script>
</head>
<body class="pop">
<p class="codetitle"><span>코드등록</span></p>
    <div class="memoplace">
<form name=frm id=frm method="POST" action="<?echo $PHP_SELF?>">
        <table cellpadding="0" cellspacing="1" border="0" class="bbsTable">
          <colgroup>
          <col width="120px" />
          <col width="*" />
          </colgroup>
          <tr>
            <th>농협명</th>
            <td><input type="text" id="jbnh_name" name="jbnh_name" title="농협명"  class="boxinput w97p"/></td>
          </tr>
		  <tr>
            <th>품목</th>
            <td>
<?
	$list = Code_GetSelect('A', '1', null);
	
	if ($list->getLength() > 0 )
	{
		while ($list->hasNext())
		{
			$row 			= & $list->next();
			$code_code1		= $row->getString('CODE_CODE1');
			$code_name		= $row->getString('CODE_NAME');
?>
				<input type="checkbox" id="nhcode_item1[]" name="nhcode_item1[]" value="<?echo $code_code1?>" /> <?echo $code_name?>
<?
		}
	}
?>
			</td>
          </tr>
        </table>
        <div class="BtnList">
            	<ul>
                	<li><input type="submit" id="sbmtBtn" name="sbmtBtn" class="btn_submit" value=""/></li>
					<li><input type="button" class="btn_cancel" onClick="MNG.fncRtnfunc('rst','NH');" title="취소"/></li>
					<input type="hidden" name="mode" id="mode" value="r"/>
                </ul>
            </div>
</form>
	</div>
</body>
</html>
<?
	}
?>